//
//  WDProductDetailCellTableViewCell.m
//  Zhihuijinfu
//
//  Created by 王笛 on 2016/12/12.
//  Copyright © 2016年 王笛. All rights reserved.
//

#import "WDParentDetailCell.h"
#import "WDParentDetail.h"

@interface WDParentDetailCell ()
@property(nonatomic, weak) UIImageView *iconView;
@property(nonatomic, weak) UILabel *descLabel;
@property(nonatomic, weak) UILabel *valueLabel;
@end

@implementation WDParentDetailCell

+ (instancetype)parentDetailCellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"parentDetailCell";
    WDParentDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell ==nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        UIImageView *iconView = [[UIImageView alloc] init];
        [self.contentView addSubview:iconView];
        self.iconView = iconView;
        
        [iconView makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(20);
            make.centerY.equalTo(self.contentView.centerY);
        }];
        [iconView layoutIfNeeded];
        
        UILabel *descLabel = [[UILabel alloc] init];
        descLabel.font = [UIFont systemFontOfSize:15];
        descLabel.textColor = ColorForRGB(0x6b6b6b);
        [self.contentView addSubview:descLabel];
        self.descLabel = descLabel;
        
        [descLabel makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(iconView.right).offset(15);
            make.centerY.equalTo(self.contentView.centerY);
        }];
        [descLabel layoutIfNeeded];
        
        UILabel *valueLabel = [[UILabel alloc] init];
        valueLabel.font = [UIFont systemFontOfSize:15];
        valueLabel.textColor = ColorForRGB(0xa0a0a0);
        valueLabel.lineBreakMode = UILineBreakModeCharacterWrap;
        valueLabel.numberOfLines = 0;
        [self.contentView addSubview:valueLabel];
        self.valueLabel = valueLabel;
        
        [valueLabel makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(descLabel.right).offset(5);
            make.centerY.equalTo(self.contentView.centerY);
            make.right.equalTo(self.contentView.right).offset(-30);
        }];
    }
    return self;
}

- (void)setParentDetail:(WDParentDetail *)parentDetail
{
    _parentDetail = parentDetail;
    self.iconView.image = [UIImage imageNamed:parentDetail.icon];
    self.descLabel.text = parentDetail.desc;
    self.valueLabel.text = parentDetail.value;
}

- (void)setTextColor:(UIColor *)textColor
{
    _textColor = textColor;
    self.valueLabel.textColor = textColor;
}

- (void)setValue:(NSString *)value
{
    _value = value;
    
    if (![value isEqualToString:@""]) {
        self.valueLabel.text = value;
    }
}

@end
